/*
 * User: rant
 * Date: Aug 13, 2007
 *
 *
 */
package laMalinche.testingPlayGround.swingTest;

import laMalinche.testingPlayGround.testModel.PersonVo;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.lang.reflect.Method;
import java.util.*;
import java.awt.*;

/**
 *
 */
public class PropertyEditor extends JPanel {
	private final PersonVo person;
	private JTextField jTextField;

	public PropertyEditor(PersonVo personVo, String... fields) {
        person = personVo;
		Set<String> props = new HashSet<String>();
		for (final String field : fields) {
			props.add(field);
            try {
				final String name1 = "get" + field;
                Method method = personVo.getClass().getMethod(name1);
                Object o = method.invoke(person);
                if (o==null) {
                    o = "";
                }
				add(new JLabel(person.getOgnl() + field + ": " ));
				 jTextField = new JTextField(o.toString(),11);

				add(jTextField);
			} catch (Exception e) {
				System.out.print(e);

			}
		}
        setAlignmentX(LEFT_ALIGNMENT);
        setLayout(new FlowLayout(FlowLayout.LEFT));
    }
	int  getValue(){
		 String s = jTextField.getText();
		if (s == null || s.length() == 0){
			s ="0";
		}
		return new Integer(s);

	 }
}